#include<iostream>
#include<stdio.h>
#include"tools.h"
#include"manager.h"
#include"managerview.h"
#include"managerservice_impl.h"
#include"managerview_console_impl.h"

using namespace std;

void ManagerViewConsolelmpl::menu()
{
	clears();
	cout << "ManagerView" << endl;
	cout << "1.add" << endl;
	cout << "2.delete" << endl;
	cout << "3.list" << endl;
	cout << "4.return" << endl;

	while(1)
	{
	clears();
	cout << "ManagerView" << endl;
	cout << "1.add" << endl;
	cout << "2.delete" << endl;
	cout << "3.list" << endl;
	cout << "4.return" << endl;

		int num;
		cin >> num;
		switch(num)
		{
			case 1:add();break;
			case 2:del();break;
			case 3:list();break;
			case 4:return;
		}
	}
}

bool ManagerViewConsolelmpl::add()
{
	Manager manager;
	char _name[20]="";
	char _password[20]="";
	cout << "please input name:";
	cin >> _name;
	manager.change_name(_name);
	cout << "please input password:";
	get_pwd(_password,20);
	manager.change_password(_password);
	int num = get_id("./account/id.dat");
	manager.change_id(num);

	service->addManager(manager);
	clear_stdin();
	anykey_continue();
	return true;
}

bool ManagerViewConsolelmpl::del()
{
	Manager manager;
	cout << "please input id:";
	int num;
	cin >> num;
	manager.change_id(num);
	service->deleteManager(manager.get_manager_id());
	clear_stdin();
	anykey_continue();
	return true;
}

void ManagerViewConsolelmpl::list()
{
	service->listManager();
	clear_stdin();
	anykey_continue();
}
